#!/bin/sh

_pkg_installed() {
    echo $(($(xbps-query -l | grep $1 | wc -l)))
}

cd ~
ln -sf ~/dotfiles/.aliases ~/.aliases
echo "ln -sf ~/dotfiles/.aliases ~/.aliases"
ln -sf ~/dotfiles/.xinitrc ~/.xinitrc
echo "ln -sf ~/dotfiles/.xinitrc ~/.xinitrc"
ln -sf ~/dotfiles/.xprofile ~/.xprofile
echo "ln -sf ~/dotfiles/.xprofile ~/.xprofile"
ln -sf ~/dotfiles/.profile ~/.profile
echo "ln -sf ~/dotfiles/.profile ~/.profile"
#ln -sf ~/dotfiles/.mkshrc ~/.mkshrc
#echo "ln -sf ~/dotfiles/.mkshrc ~/.mkshrc"
ln -sf ~/dotfiles/.bashrc ~/.bashrc
echo "ln -sf ~/dotfiles/.mkshrc ~/.mkshrc"
ln -sf ~/dotfiles/.bash_profile ~/.bash_profile
echo "ln -sf ~/dotfiles/.mkshrc ~/.mkshrc"
ln -sf ~/dotfiles/.urlview ~/.urlview
echo "ln -sf ~/dotfiles/.urlview ~/.urlview"
ln -sf ~/dotfiles/.xbindkeysrc ~/.xbindkeysrc 
echo "ln -sf ~/dotfiles/.xbindkeysrc ~/.xbindkeysrc"
ln -sf ~/dotfiles/.config/dunst/.dunstrc ~/.config/dunst/.dunstrc
echo "ln -sf ~/dotfiles/.config/dunst/.dunstrc ~/.config/dunst/.dunstrc"

# xq -l:
#  your pkg manager here, where the query returns 1 line or none
# grep newsboat
#  your package for newsboat here, depending which name pkg sources use
if [ $(_pkg_installed newsboat) -eq 1 ]; then
    ln -sf ~/dotfiles/.newsboat/config ~/.newsboat/config
    echo "ln -sf ~/dotfiles/.newsboat/config ~/.newsboat/config"
    ln -sf ~/dotfiles/.newsboat/urls ~/.newsboat/urls
    echo "ln -sf ~/dotfiles/.newsboat/urls ~/.newsboat/urls"
fi

if [ $(_pkg_installed ghc) -eq 1 ]; then
    ln -sf ~/dotfiles/.ghci ~/.ghci
    echo "ln -sf ~/dotfiles/.ghci ~/.ghci"
fi

if [ $(_pkg_installed qutebrowser) -eq 1 ]; then
    cp -r ~/dotfiles/.config/qutebrowser ~/.config
    echo "cp -r ~/dotfiles/.config/qutebrowser ~/.config"
    cp -r ~/dotfiles/.local/share/qutebrowser ~/.local/share
    echo "cp -r ~/dotfiles/.local/share/qutebrowser ~/.local/share"
fi

[ ! -d ./bin ] &
    cp -r ~/dotfiles/bin .
echo "cp -r ~/dotfiles/bin ."
[ ! -d ./.config ] &
    cp -r ~/dotfiles/.config .
echo "cp -r ~/dotfiles/.config ."

# bgs
rm -rf ~/.config/walls
echo "rm -rf ~/.config/walls"
cp -r ~/dotfiles/.config/walls ~/.config/
echo "cp -r ~/dotfiles/.config/walls ~/.config/"

# vis
cd /usr/share/vis
sudo cp ~/dotfiles/vis/visrc.lua .
echo "sudo cp ~/dotfiles/vis/visrc.lua ."
sudo cp ~/dotfiles/vis/themes/* ./themes/
echo "sudo cp ~/dotfiles/vis/themes/* ./themes/"
sudo cp ~/dotfiles/vis/plugins/* ./plugins/
echo "sudo cp ~/dotfiles/vis/plugins/* ./plugins/"

# mnt
cd ~
mkdir -p ~/1mnt ~/2mnt ~/3mnt
echo "mkdir -p ~/1mnt ~/2mnt ~/3mnt"

# backlight
[ $PERSONALDEVICE -eq 1 ] &&
    sudo sudo cp ~/dotfiles/.config/udev/20-backlight.rules /usr/lib/udev/rules.d/20-backlight.rules &&
    echo "sudo cp ~/dotfiles/.config/udev/20-backlight.rules /usr/lib/udev/rules.d/20-backlight.rules"
